<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>dom事件流</title>
    <style>
        #outer {
            width: 300px;
            height: 300px;
            background-color: red;
            overflow: hidden;
            margin: 50px;
        }
        #center {
            width: 200px;
            height: 200px;
            background-color: yellow;
            overflow: hidden;
            margin: 50px;
        }
        #inner {
            width: 100px;
            height: 100px;
            background-color: green;
            margin: 50px;
        }
    </style>
</head>
<body>
    <div id="outer">
        <div id="center">
            <div id="inner"></div>
        </div>
    </div>
    <script>
        /*
        冒泡阶段的写法
        */
        inner.onclick = function (e) {
            console.log('inner click');
        };
        center.onclick = function (e) {
            console.log('center click');
        };
        outer.onclick = function (e) {
            console.log('outer click');
        };
        document.body.onclick = function (e) {
            console.log('body click');
        };
        document.documentElement.onclick = function (e) {
            console.log('html click');
        };
        document.onclick = function (e) {
            console.log('document click');
        };
        window.onclick = function (e) {
            console.log('window click');
        };
        /*
        捕获阶段的写法
        */
        inner.addEventListener('click', function (e) {
            console.log('inner addEventListener click');
        }, true);
        center.addEventListener('click', function (e) {
            console.log('center addEventListener click');
        }, true);
        outer.addEventListener('click', function (e) {
            console.log('outer addEventListener click');
        }, true);
        document.body.addEventListener('click', function (e) {
            console.log('body addEventListener click');
        }, true);
        document.documentElement.addEventListener('click', function (e) {
            console.log('html addEventListener click');
        }, true);
        document.addEventListener('click', function (e) {
            console.log('document addEventListener click');
        }, true);
        window.addEventListener('click', function (e) {
            console.log('window addEventListener click');
        }, true);
    </script>
</body>
</html>